package com.fast.framework.core.page;

import io.swagger.annotations.ApiModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import java.util.List;

/**
 * 分页实体类
 *
 * @param <T>
 */
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value = "分页实体类", description = "分页实体类")
public class ResponsePage<T> {
    private int currentPage;  // 当前页码
    private int pageSize;     // 每页记录数
    private long totalRecords; // 总记录数
    private int totalPages;   // 总页数
    private List<T> dataList; // 当前页的数据列表
    private boolean hasNextPage; // 是否有下一页
    private boolean hasPreviousPage; // 是否有上一页

    public ResponsePage() {
    }

    public ResponsePage(int currentPage, int pageSize, long totalRecords, List<T> dataList) {
        this.currentPage = currentPage;
        this.pageSize = pageSize;
        this.totalRecords = totalRecords;
        this.dataList = dataList;
        this.totalPages = (int) Math.ceil((double) totalRecords / pageSize);
        this.hasNextPage = currentPage < totalPages;
        this.hasPreviousPage = currentPage > 1;
    }
}
